'''
Created on 24 Mar 2012

@author: R
'''

import socket
from urllib import urlopen
import urllib2

def processpage(url,proxy):
    if proxy=="0":
        socket.setdefaulttimeout(20) #try except @line 30: read()
        try:
            page = urlopen(url)
            print ("connecting",url)
            content = page.read().decode("gbk").encode("utf-8")
            print "open link success"
            page.close()
            return content
        except IOError:
            print ("timeout, link=",url)
    else:
        try:
            proxy_support = urllib2.ProxyHandler({'http':proxy})
            opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
            urllib2.install_opener(opener)
            return urllib2.urlopen(url).read().decode("gbk").encode("utf-8")
        except:
            print "proxy error"
        
        
def search_term(regular_search):
    if regular_search == None: 
        print ("unknow group")
        regular_search = "N/A"
    else:
        regular_search = regular_search.group(1)
    return regular_search.rstrip("&nbsp;")


if __name__ == '__main__':
    pass